<?php

namespace component\extend\emailsms;

use component\extend\Isms;
use Exception;
use Noodlehaus\Config;
use PHPMailer\PHPMailer\PHPMailer;

class Index implements Isms
{
    public function send(array $param = [])
    {
        try {
            $config = Config::load(__DIR__ .  '/config.ini');
            $config = $config['value'];
            $mail = new PHPMailer(true);
            $mail->CharSet = 'utf-8';
            //  $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
            $mail->isSMTP();                                            //Send using SMTP
            $mail->Host       = $config['host'];                     //Set the SMTP server to send through
            $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
            $mail->Username   =  $config['username'];                    //SMTP username
            $mail->Password   =  $config['password'];                               //SMTP password
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;            //Enable implicit TLS encryption
            $mail->Port       =  $config['Port'];                                     //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`

            $mail->setFrom($config['username']);
            //Recipients
            $mail->addAddress($param['data']['email']);


            //Content
            $mail->isHTML(true);                                  //Set email format to HTML
            $mail->Subject = $param['message']['title'];
            $mail->Body    = $param['message']['content'];

            $mail->send();
        } catch (Exception $ex) {
            throw $ex;
        }
    }
}
